package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallBrandGrandMapper;
import org.linlinjava.litemall.db.domain.LitemallBrandGrand;
import org.linlinjava.litemall.db.domain.LitemallBrandGrandExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author: weilai 各公司的评分.第一项为commodityComment商品评论表中的review(bigDecimal)评分
 * @date: 2020/4/25
 * @description:
 */
@Service
public class LitemallBrandGrandService {

    @Resource
    private LitemallBrandGrandMapper brandGrandMapper;
    //增加一个
    public void addBrandGrand(LitemallBrandGrand brandGrand){
        brandGrandMapper.insertSelective(brandGrand);
    }
    //删除: 主键
    public void delBrandGrandByKey(Integer id){
        brandGrandMapper.deleteByPrimaryKey(id);
    }
    //删除: brandId
    public void delBrandGrandByBrandId(Integer brandId){
        LitemallBrandGrandExample example = new LitemallBrandGrandExample();
        LitemallBrandGrandExample.Criteria criteria = example.createCriteria();
        criteria.andBrandIdEqualTo(brandId);
        brandGrandMapper.deleteByExample(example);
    }

    //更新: 一个
    public void updateBrandGrand(LitemallBrandGrand brandGrand){
        brandGrandMapper.updateByPrimaryKey(brandGrand);
    }
    //查:全部
    public List<LitemallBrandGrand> allBrandGrands(){
        LitemallBrandGrandExample example = new LitemallBrandGrandExample();
        return    brandGrandMapper.selectByExampleSelective(example);
    }
    //查: brandID  //找到各等级评分
    public List<LitemallBrandGrand> findByBrandId(Integer brandId){
        LitemallBrandGrandExample example = new LitemallBrandGrandExample();
        LitemallBrandGrandExample.Criteria criteria = example.createCriteria();
        criteria.andBrandIdEqualTo(brandId);
        return   brandGrandMapper.selectByExample(example);
    }

    public Set<Integer> brandIdList(){
        return   brandGrandMapper.allBrandIdSet();
    }

}
